"""
1. 将ORM模型映射到数据库中
"""
import os
import sys

path = os.path.dirname(__file__)
sys.path.append(os.path.join(path, ".."))

from sqlalchemy import Column, Integer, String
from conf.mysql_config import BASE


class Person(BASE):
    # 1.定义数据库表名
    __tablename__ = 'person'
    # 2.定义数据库字段及字段类型
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(50), comment='姓名', doc={'zh': '姓名'})
    country = Column(String(50), comment='国家', doc={'zh': '国家'})

    def __str__(self):
        return f"""<Person name={self.name}, country={self.country}>"""

    __repr__ = __str__


# 3. 映射数据库
BASE.metadata.create_all()
